<?php

namespace App\Http\Requests\Admin\AdminDiscount;

use App\Http\Requests\Request;

class DiscountStoreRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 验证规则
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            'discount_name' => 'required',
            'discount_type'=>'required',
            'discount_value' => 'required|numeric',
            // 'limit_amount' => 'required|numeric',
            'use_id_str'=>'required_if:discount_type,2|required_if:discount_type,3|required_if:discount_type,4|required_if:discount_type,5',
            'start_time'=>'required|date',
            'end_time'=>'required|date|after:start_time',
        ];

        return $rules;

    }

    /**
     * 验证信息
     * @return array
     */

    public function messages()
    {
        return [
            'discount_name.required' => '请填写限时折扣活动名称',
            'discount_type.required'=>'请填写限时折扣活动使用类型',
            'discount_value.required'=>'请填写限时折扣活动折扣百分比',
            // 'limit_amount.required'=>'请填写限时折扣活动限用商品数量',
            'use_id_str.required_if'=>'请选择值',
            'start_time.required'=>'请填写限时折扣活动可用的开始时间',
            'end_time.required'=>'请填写限时折扣活动可用的结束时间',

            'discount_value.numeric'=>'限时折扣活动折扣百分比必须为1-99的数字',
            // 'limit_amount.numeric'=>'限用商品数量必须为数字',

            'start_time.date'=>'开始时间必须为时间格式',
            'end_time.date'=>'结束时间必须为时间格式',
            'end_time.after'=>'结束时间必须大于开始时间',
        ];
    }
}//end class
